module.exports = {
  format: function (value) {
    if (value === null || value === undefined) return '-'
    
    let isMinus = value < 0 // 是否是负数
    
    value = isMinus ? value.toString().substr(1) : value.toString()
    value = value.replace(/^(\d*)$/, '$1.')
    value = (`${value}00`).replace(/(\d*\.\d\d)\d*/, '$1')
    value = value.replace('.', ',')
    const re = /(\d)(\d{3},)/
    
    while (re.test(value)) {
      value = value.replace(re, '$1,$2')
    }
    
    value = value.replace(/,(\d\d)$/, '.$1')
    
    return isMinus ? '-' + value.replace(/^\./, '0.') : value.replace(/^\./, '0.')
  }
}
